﻿<div>
    <span>基本信息</span>
    @if (DocStatus != Utils.DocStatus.View && DocStatus != Utils.DocStatus.PCView)
    {
        <div style="float: right;">
            <PopConfirmButton Color="Color.Danger" IsDisabled="@IsDeleteDisabled" OnConfirm="(() => DeleteBatch(BatchModel))" ConfirmIcon="fa-solid fa-triangle-exclamation text-danger" ConfirmButtonColor="Color.Danger" Content="@deleteMessage">删除批次</PopConfirmButton>
        </div>
    }
</div>
<ValidateForm Model="@BatchModel" ValidateAllProperties="true" style="margin-top: 1rem;" OnInvalidSubmit="OnInvalidSubmit" OnValidSubmit="OnValidSubmit">
    <GroupBox>
        <EditorForm TModel="Batch" Model="BatchModel" AutoGenerateAllItem="false" ItemsPerRow="4">
            <FieldItems>
                <EditorItem @bind-Field="@context.WarehouseNumber" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.OrderNumber" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.StoreName" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.CreatedOn" Readonly="true" />
                <EditorItem @bind-Field="@context.ProductName" Readonly="true">
                    <EditTemplate Context="value">
                        <div class="col-12 col-sm-6 col-md-3">
                            <BootstrapInput DisplayText="商品名称" ShowLabel="true" Value="@ProductService.Get(context.ProductId).Name" IsDisabled="@IsFieldReadOnly" />
                        </div>
                    </EditTemplate>
                </EditorItem>
                <EditorItem @bind-Field="@context.SupplierName" Readonly="true" />
                <EditorItem @bind-Field="@context.Number" Readonly="true" />
                <EditorItem @bind-Field="@context.LastModifiedOn" Readonly="true" />
                <EditorItem @bind-Field="@context.ProductId" Readonly="@IsFieldReadOnly">
                    <EditTemplate Context="value">
                        <div class="col-12 col-sm-6 col-md-3">
                            <BootstrapInput DisplayText="商品SKU" ShowLabel="true" Value="@ProductService.Get(context.ProductId).PId" IsDisabled="@IsFieldReadOnly" />
                        </div>
                    </EditTemplate>
                </EditorItem>
                <EditorItem @bind-Field="@context.Quantity" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.ProducedDate" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.DateDue" Readonly="IsFieldReadOnly" />
            </FieldItems>
        </EditorForm>
        <div class="col-12 col-sm-3" style="margin-top: 0.5rem;">
            <BootstrapInput @bind-Value="@ValidDateNum" Readonly="true" DisplayText="有效期" ShowLabel="true"></BootstrapInput>
        </div>
    </GroupBox>
    <div style="margin-top: 1.5rem;">
        <span>批次证照信息</span>
        <span style="color: red" hidden="@IsFieldReadOnly">上传批次证照信息前请先批次信息</span>
        @if (DocStatus == Utils.DocStatus.View)
        {
            <Table style="margin-top: 3rem;" TItem="Core.Models.BatchLicense" OnQueryAsync="OnLicenseQueryAsync"
                   IsStriped="true" IsBordered="true" SelectedRows="@SelectedLicense" SelectedRowsChanged="@SelectChanged"
                   ShowSkeleton="true" ShowEmpty="true" ShowSearch="true">
                <TableColumns>
                    <TableColumn @bind-Field="@context.Type" Width="100">
                        <Template Context="value">
                            <Tag Color="Color.Primary">@GetLicenseTypeName(value.Value)</Tag>
                        </Template>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.LId" Width="100" />
                    <TableColumn @bind-Field="@context.ValidFromDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.CreatedOn" Width="100" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" Text="状态">
                        <Template Context="value">
                            @*@if (DateTime.Compare(DateTime.Now, value.Value) > 0)*@
                            @if (!value.Row.IsPublish)
                            {
                                <Tag Color="Color.Dark">未生效</Tag>
                            }
                            else if (DateTime.Now > value.Value)
                            {
                                <Tag Color="Color.Danger">已过期</Tag>
                            }
                            else if (DateTime.Now <= value.Value)
                            {
                                <Tag Color="Color.Success">生效中</Tag>
                            }
                            else if (value.Value == null)
                            {
                                <Tag Color="Color.Success">长期有效</Tag>
                            }
                        </Template>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.Id" Text="操作">
                        <Template Context="value">
                            <Button Text="查看" OnClick="@(() => View(value.Row))" />
                        </Template>
                    </TableColumn>
                    @*<TableColumn @bind-Field="@context.Attachment.URL" Width="100" />*@
                </TableColumns>
            </Table>
            <div class="form-footer mt-3">
                <button type="button" class="btn btn-secondary" @onclick="@(e => OnClose?.Invoke())">
                    <i class="fa-solid fa-xmark"></i>
                    <span>关闭</span>
                </button>
            </div>
        }
        else if (DocStatus == Utils.DocStatus.PCView)
        {
            <Table style="margin-top: 3rem;" TItem="Core.Models.BatchLicense" OnQueryAsync="OnLicenseQueryAsync"
                   IsStriped="true" IsBordered="true" OnDoubleClickRowCallback="@View" SelectedRows="@SelectedLicense" SelectedRowsChanged="@SelectChanged"
                   ShowSkeleton="true" ShowEmpty="true" ShowSearch="true">
                <TableColumns>
                    <TableColumn @bind-Field="@context.Type" Width="100">
                        <Template Context="value">
                            <Tag Color="Color.Primary">@GetLicenseTypeName(value.Value)</Tag>
                        </Template>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.LId" Width="100" />
                    <TableColumn @bind-Field="@context.ValidFromDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.CreatedOn" Width="100" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" Text="状态">
                        <Template Context="value">
                            @*@if (DateTime.Compare(DateTime.Now, value.Value) > 0)*@
                            @if (!value.Row.IsPublish)
                            {
                                <Tag Color="Color.Dark">未生效</Tag>
                            }
                            else if (DateTime.Now > value.Value)
                            {
                                <Tag Color="Color.Danger">已过期</Tag>
                            }
                            else if (DateTime.Now <= value.Value)
                            {
                                <Tag Color="Color.Success">生效中</Tag>
                            }
                            else if (value.Value == null)
                            {
                                <Tag Color="Color.Success">长期有效</Tag>
                            }
                        </Template>
                    </TableColumn>
                    @*<TableColumn @bind-Field="@context.Attachment.URL" Width="100" />*@
                </TableColumns>
            </Table>
            <div class="form-footer mt-3">
                <button type="button" class="btn btn-secondary" @onclick="@(e => OnClose?.Invoke())">
                    <i class="fa-solid fa-xmark"></i>
                    <span>关闭</span>
                </button>
            </div>
        }
        else
        {
            <div style="float: right;">
                <Button Text="添加证照" OnClick="Add" IsDisabled="IsButtonDisabled" />
                <Button Text="编辑证照" OnClick="@EditBtn" IsDisabled="@(SelectedLicense.Count != 1)" />
                <PopConfirmButton Color="Color.Danger" IsDisabled="@(SelectedLicense.Count == 0 || IsDeleteDisabled)" OnConfirm="(() => Delete(SelectedLicense))" ConfirmIcon="fa-solid fa-triangle-exclamation text-danger" ConfirmButtonColor="Color.Danger" Content="确定删除选中的记录吗？">删除证照</PopConfirmButton>
            </div>
            <Table style="margin-top: 3rem;" TItem="Core.Models.BatchLicense" OnQueryAsync="OnLicenseQueryAsync"
                   IsStriped="true" IsBordered="true" IsMultipleSelect="true" OnDoubleClickRowCallback="@Edit" SelectedRows="@SelectedLicense" SelectedRowsChanged="@SelectChanged"
                   ShowSkeleton="true" ShowEmpty="true" ShowSearch="true">
                <TableColumns>
                    <TableColumn @bind-Field="@context.Type" Width="100">
                        <Template Context="value">
                            <Tag Color="Color.Primary">@GetLicenseTypeName(value.Value)</Tag>
                        </Template>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.LId" Width="100" />
                    <TableColumn @bind-Field="@context.ValidFromDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.CreatedOn" Width="100" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" Text="状态">
                        <Template Context="value">
                            @*@if (DateTime.Compare(DateTime.Now, value.Value) > 0)*@
                            @if (!value.Row.IsPublish)
                            {
                                <Tag Color="Color.Dark">未生效</Tag>
                            }
                            else if (DateTime.Now > value.Value)
                            {
                                <Tag Color="Color.Danger">已过期</Tag>
                            }
                            else if (DateTime.Now <= value.Value)
                            {
                                <Tag Color="Color.Success">生效中</Tag>
                            }
                            else if (value.Value == null)
                            {
                                <Tag Color="Color.Success">长期有效</Tag>
                            }
                        </Template>
                    </TableColumn>
                    @*<TableColumn @bind-Field="@context.Attachment.URL" Width="100" />*@
                </TableColumns>
            </Table>
            <div class="form-footer mt-3">
                <button type="button" class="btn btn-secondary" @onclick="@(e => OnClose?.Invoke())">
                    <i class="fa-solid fa-xmark"></i>
                    <span>关闭</span>
                </button>
                <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa-solid fa-floppy-disk" Text="保存" IsDisabled="@IsSaveDisabled" />
            </div>
        }
    </div>
</ValidateForm>